"use strict";
cc._RF.push(module, '801b27g+jxJvoKdb2r+SKDV', 'NativeSound');
// Script/Ssg/API/Native/NativeSound.js

'use strict';

var playMusicId = {};

var NativeSound = cc.Class({

    statics: {

        /**
         * 播放音效
         * @param fileName
         */
        playEffect: function playEffect(fileName) {
            var url = this.getFileUrl(fileName, true);
            cc.loader.load(url, function (err, res) {
                if (err) {
                    Log.error(err.message || err);
                    return;
                }
                cc.audioEngine.play(res);
            });
        },

        playMusic: function playMusic(fileName, isLoop) {
            var url = 'Sound/' + fileName;
            var self = this;
            cc.loader.loadRes(url, type, function (err, res) {
                if (err) {
                    Log.error('---------loadRes err: ' + err);
                    return;
                }
                self.playMusicId[fileName] = cc.audioEngine.play(res, true);
            });
        },

        stopMusic: function stopMusic(fileName) {
            if (!fileName) {
                cc.audioEngine.stopAll();
                return;
            }
            cc.audioEngine.stop(this.playMusicId[fileName]);
            this.playMusicId[fileName] = -1;
        },

        /**
         * 暂停音乐
         * @param fileName
         */
        pauseMusic: function pauseMusic(fileName) {
            if (fileName) {
                cc.audioEngine.pause(this.playMusicId[fileName]);
            }
            cc.audioEngine.pauseAll();
        },

        /**
         * 恢复音乐播放
         * @param fileName
         */
        resumeMusic: function resumeMusic(fileName) {
            if (fileName) {
                cc.audioEngine.resume(this.playMusicId[fileName]);
                return;
            }
            cc.audioEngine.resumeAll();
        },

        getFileUrl: function getFileUrl(fileName, isAssets) {
            if (fileName == '') {
                return '';
            }
            if (isAssets) {
                return cc.url.raw('resources/Sound/' + fileName);
            }
            return fileName;
        }

    }
});

module.exports = NativeSound;

cc._RF.pop();